package net.zjitc.listthree.web;

import net.zjitc.listthree.dao.UserDao;
import net.zjitc.listthree.dao.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Administrator
 * @Date 2020/6/19 11:17
 **/
@WebServlet("/delUser")
public class DelUser extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        /*1.获取请求参数（id）
         * 2.调用dao方法完成删除用户功能
         * 3.想要看到删除后最新数据，重定向到userListServlet*/
        String ids= request.getParameter("id");
        /*String转int*/
        int id=Integer.parseInt(ids);
        UserDao dao=new UserDaoImpl();
        dao.delete(id);
        /*重定向*/
        String contextPath = request.getContextPath();
        response.sendRedirect(contextPath+"/userListServlet");
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
